<?php
$post = $_POST;
$link=mysqli_connect('127.0.0.1','root','root','books-system');
mysqli_set_charset($link, 'utf8');

//新增用户信息
$username = $post['username'];
$name = $post['name'];
$sex = $post['sex'];
$password = $post['password'];
$phone = $post['phone'];
$emali = $post['emali'];
$query = "select * from user WHERE username='$username'";

$check = mysqli_query($link,$query );
$test=mysqli_fetch_all($check,MYSQLI_ASSOC);

if ($test[0]['password']) {
    $run = "UPDATE user SET name='$name',sex='$sex',password='$password',phone='$phone',emali='$emali' WHERE username='$username'";
} else {
    $run= "INSERT INTO user (username,name,sex,password,phone,emali) VALUES ('$username','$name','$sex','$password','$phone','$emali')";
}


$result = mysqli_query($link, $run);

// print_r($run);
if ($result) {
    echo '<script>alert("成功，点确定按钮后返回！");</script>';
    header("refresh:0;url=user-edit.php?username=$username");
} else {
    echo '<script>alert("失败，点确定按钮后返回！");</script>';
    header("refresh:0;url=user-edit.php?username=$username");
}
?>